package com.li.test.base;

import java.math.BigInteger;

public class LeetCode {
    public int reverse(Integer x) {
        if(x>Integer.MAX_VALUE){
            x=Integer.MAX_VALUE;
        }
        String aa = "";
        String hh = String.valueOf(x);
        if (hh.contains("-")) {
            aa = "-";
            hh = hh.replace("-", "");
        } else if (hh.contains("+")) {
            aa = "+";
            hh = hh.replace("+", "");
        }
        String[] zz = hh.split("");
        for (int i = zz.length - 1;i < zz.length; i--) {
            if(i<0){
                break;
            }
            aa = aa + zz[i];
        }
        int r = Integer.valueOf(aa);
        if(r>Integer.MAX_VALUE || r<Integer.MIN_VALUE){
            return 0;
        }

        return r;
    }
    public int reverse2(int x) {
        if(x>Integer.MAX_VALUE){
            x=Integer.MAX_VALUE;
        }
        long r = 0;
        while(x!=0){
            int pop = x % 10;
            x = (x-pop)/10;
            r = r*10 + pop;
        }
        if(r>Integer.MAX_VALUE || r<Integer.MIN_VALUE){
            return 0;
        }
        return (int)r;
    }
    public int stringLength(String str){
        String[] aa = str.split(" ");
        return aa[aa.length-1].length();
    }
    public static void main(String[] args) {
        LeetCode lc = new LeetCode();
        int  len = 1534236469;
        int c = lc.stringLength("hello nowcoder");
        System.out.println(lc.reverse( len));
    }
}
